package org.murphy.mock_spring.implement;

import org.murphy.mock_spring.interfaces.Container;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: murphy_mock
 * @description: default implement container (Singleton)
 * @author: 45048254 Murphy C Wang
 * @create: 2019-06-19 18:53
 **/
public class DefaultContainer implements Container {
    private static DefaultContainer container;

    private DefaultContainer() {
    }

    public static Container instanse() {
        if (container == null) {
            synchronized (DefaultContainer.class) {
                if (container == null) {
                    container = new DefaultContainer();
                }
            }
        }
        return container;
    }

    //Container himself
    Map<String,Object> beans = new HashMap<>();

    @Override
    public Object getBean(String beanName) {
        return beans.get(beanName);
    }

    @Override
    public Object getBean(Class clazz) {
        return null;
    }

    @Override
    public void addBean(String name, Object bean) {
        this.beans.put(name, bean);
    }
}
